package com.mastercard.assets.web.struts.actions;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.mastercard.assets.web.util.to.UserLogin;

public class CrearNotificacion
	extends
		Action
{
	public ActionForward execute(
							ActionMapping mapping , 
							ActionForm form ,
							HttpServletRequest request , 
							HttpServletResponse response )
		throws 
			IOException , 
			ServletException
	{
		HttpSession session = request.getSession( ) ;
		
		// en caos de null
		if( session == null )
			return mapping.findForward( "noLogin" ) ;
		
		// toma el userLogin
		UserLogin user = ( UserLogin ) session.getAttribute( "UserLogin" ) ;
		
		// en caso de null
		if( user == null )
			return mapping.findForward( "noLogin" ) ;
		
		String operation = request.getParameter( "operation" ) ;
		String tipoNotificacion = request.getParameter( "tipoNotificacion" ) ;
		String cveAlerta = request.getParameter( "cveAlerta" ) ;
		String cveRole = request.getParameter( "cveRole" ) ;
		String cveNivel = request.getParameter( "cveNivel" ) ;
		String tipo = request.getParameter( "tipo" ) ;
		String mail = request.getParameter( "mail" ) ;
		String cveNotificacion = request.getParameter( "cveNotificacion" ) ;
		
		// en caso de que se cumpla, guarda el WorkArea
		user.setNextWorkArea( "/CrearNotificacionIn.do?" + 
				( ( operation != null ) ? "operation=" + operation : "&operation=" ) +
				( ( tipoNotificacion != null ) ? "&tipoNotificacion=" + tipoNotificacion : "&tipoNotificacion=" ) +
				( ( cveAlerta != null ) ? "&cveAlerta=" + cveAlerta : "&cveAlerta=" ) +
				( ( cveRole != null ) ? "&cveRole=" + cveRole : "&cveRole=" ) +
				( ( cveNivel != null ) ? "&cveNivel=" + cveNivel : "&cveNivel=" ) +
				( ( tipo != null ) ? "&tipo=" + tipo : "&tipo=" ) +
				( ( cveNotificacion != null ) ? "&cveNotificacion=" + cveNotificacion : "&cveNotificacion=" ) +
				( ( mail != null ) ? "&mail=" + mail : "&mail=" )
				) ;
		
	  	return mapping.findForward( "success" ) ;
	}
	
}
